# 写函数，获取列表元组奇数位元素，返回列表
"""
def odd_index(a):
    lst =[]
    for i in range(1, len(a), 2):
        lst.append(a[i])
    return lst


lst = [1, 2, 3, 4, 5, 6]
tup = (1, 5, 6, 7)
print(odd_index(tup))"""
# 写函数,判断输入的对象长度是否大于5
"""

def if_over_5(a):
    # if len(a) > 5:
    #     return "Yes"
    # else:
    #     return "No"
    # 三元运算符
    return Ture if len(a) > 5: False
    # 表达式
    return len(a)>5 
    
    
s = "23145689"
lst = [1, 2, 3, 4, 5, 6]
tup = (1, 5, 6, 7)
print(if_over_5(tup))"""

# 写函数，传入列表，length大于二返回前两个元素
"""
def top_tow(a):
    # if len(a) > 2:
    #     lst = [a[0], a[1]]
    #     return lst
    # else:
    #      return a
    # 三元运算符
    return  a[:2] if len(a) > 2 else a
    # 切片
    return a[:2]


lst = [1, 2, 3]
print(top_tow(lst))
print(lst)
"""


# 写函数，记录传入字符串中数字，字母，以及其他的个数
"""
def split_str(a):
    dic = {"数字":0, "字母":0, "其他":0}
    for i in a:
        if i.isalpha():
            dic["字母"] += 1
        elif i.isdecimal():
            dic["数字"] += 1
        else:
            dic["其他"] +=1
    return dic


s = '12321lkhkj==='
print(split_str(s))
"""

# 比较两数的大小
"""
def is_max(int1, int2):
    return int1 if int1 > int2 else int2


print(is_max(5, 14))
"""

# 传入字典，判读值的长度，大于二，取前两个返回
"""

def top2_value(dic):
    for i in dic:
        dic[i] = dic[i][0:2]
    return dic


dic = {"k1": "v1v1", "k2": [11, 22, 33]}
print(top2_value(dic))
"""


# 写函数，将传入的列表返回为字典
"""

def to_dict(a):
    dic = {}
    for i in range(len(a)):
        dic[i] = a[i]
    return dic


lst = [1, 2, 3, 4, 5]
print(to_dict(lst))
"""


# 输入 姓名 性别 年龄 学历 将这些信息追加到student_msg文件中
"""

def stu_msg(name, sex, age, edc, ):
    with open("student_mag", 'a', encoding='utf-8') as f:
        f.write(f'{name},{sex},{age},{edc}\n')


while True:
    print("1 输入\nq\\Q 退出")
    choose = input('请选择:')
    if choose == '1':
        # 基本操作
        # name1 = input('姓名:')
        # sex1 = input('性别:')
        # age1 = input('年龄:')
        # edc1 = input('学历:')
        # stu_msg(name=name1, sex=sex1, age=age1, edc=edc1)
        # 链式操作
        n, s, a, e = input("输入姓名，性别，年龄，学历，以逗号隔开").strip().\
            replace('，', ',').split(',')
        stu_msg(name=n, sex=s, age=a, edc=e)
    elif choose.lower() == 'q':
        break

"""


# 输入文件名，修改内容，来执行修改文件的操作
"""

def change_file(name, old, new):
    new_name = name+'1'
    with open(name, 'r', encoding='utf-8') as f,\
            open(new_name, 'w', encoding='utf-8') as f1:
        for i in f:
            f1.write(i.replace(old, new))
    # 改名
    import os     
    os.rename(name, name+'_backup')
    os.rename(new_name, name)


change_file("student_mag", '本科', '在校大学生')
"""




